home *** CD-ROM | disk | FTP | other *** search
/ Amiga Plus Special 16 / AMIGAplus Sonderheft 16 (1998)(ICP)(DE)[!].iso / pd / anwendungen / ispell-3.1.18src / iwhich < prev    next >
Text File  |  1995-01-23  |  1KB  |  75 lines

  1. : Use /bin/sh
  2. #
  3. # $Id: iwhich,v 1.1 1995/01/15 00:13:54 geoff Exp $
  4. #
  5. # Report which version of a command is in use.  This version of
  6. # "which" doesn't handle shell aliases, but it makes up for that with
  7. # the "-a" (report all copies) switch and the fact that it returns a
  8. # nonzero shell status if the command isn't found.
  9. #
  10. USAGE='Usage:  which [-a] command[s]'
  11. #
  12. # For each command, the full pathname of the version that will be
  13. # selected from $PATH is reported.  If the -a switch is given,
  14. # versions in $PATH that are overridden by earlier $PATH entries will
  15. # also be reported.  The exit status is nonzero if none of the
  16. # commands are found anywhere in $PATH.
  17. #
  18. # $Log: iwhich,v $
  19. # Revision 1.1  1995/01/15  00:13:54  geoff
  20. # Initial revision
  21. #
  22. #
  23. opath=$PATH
  24. PATH=/bin:/usr/bin
  25. all=no
  26. while [ $# -gt 0 ]
  27. do
  28.     case "$1" in
  29.     -a)
  30.         all=yes
  31.         shift
  32.         ;;
  33.     -*)
  34.         echo "$USAGE" 1>&2
  35.         exit 2
  36.         ;;
  37.     *)
  38.         break
  39.         ;;
  40.     esac
  41. done
  42. case $# in
  43.     0)
  44.     echo "$USAGE" 1>&2
  45.     exit 2
  46.     ;;
  47. esac
  48. opath=`echo "$opath" | sed 's/^:/.:/
  49.               s/::/:.:/g
  50.               s/:$/:./
  51.               s/:/ /g'`
  52. found=false
  53. for file
  54. do
  55.     for i in $opath
  56.     do
  57.     if [ -x $i/$file -a ! -d $i/$file ]
  58.     then
  59.         echo $i/$file
  60.         found=true
  61.         case "$all" in
  62.         no)
  63.             break
  64.             ;;
  65.         esac
  66.     fi
  67.     done
  68. done
  69. if $found
  70. then
  71.     exit 0
  72. else
  73.     exit 1
  74. fi
  75.